/*
 * packet.h
 *
 *  Created on: Aug 20, 2024
 *      Author: 31652
 */

#ifndef INC_CK156_PACKET_H_
#define INC_CK156_PACKET_H_

#include "ring_buffer.h"

#define PacketHead 0x20
#define PacketTail 0x03

typedef void(*OnTag)(uint8_t* uid); // OnTag(UID:string)
typedef void(*TagOperateCallback)(uint8_t success, uint8_t* data, uint8_t err_code); // TagOperateCallback(success:1/0, data, error_num)

extern void OnPacket(uint8_t* packet, uint8_t dataLen);
extern void OnTx(uint8_t *data, uint32_t len);

uint8_t* GetPacketBuffer();
void SendTxData(uint8_t *data, uint32_t len);
void OnNewData(i_ringbuffer* dataBuf);

void OnPacket(uint8_t* packet, uint8_t length);

void SetTagListener(OnTag listener);
void RemoveTagListener();

void SelectTag(uint8_t* uid);

uint8_t Read_Tag(uint8_t fromBlock, uint8_t blockQty, uint8_t* payload, TagOperateCallback cb);
uint8_t Write_Tag(uint8_t fromBlock, uint8_t blockQty, uint8_t* payload, TagOperateCallback cb);

uint8_t Lock_Tag(uint8_t fromBlock, uint8_t blockQty);

#endif /* INC_CK156_PACKET_H_ */
